home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-06-24 | 10.3 KB | 383 lines | [TEXT/MPS ] |
- // Copyright © 1994-95 by Apple Computer, Inc. All rights reserved.
- // UDrawShapes.cp
-
- #ifndef __UDRAWSHAPES__
- #include "UDrawShapes.h"
- #endif
-
- // DrawShapes
-
- #ifndef __BETTERFEEDBACK__
- #include "BetterFeedback.h"
- #endif
-
- #ifndef __HACKMENU__
- #include "HackMenu.h"
- #endif
-
- #ifndef __PATTERNMENU__
- #include "PatternMenu.h"
- #endif
-
- #ifndef __TOOLSMENU__
- #include "ToolsMenu.h"
- #endif
-
- #ifndef __USHAPES__
- #include "UShapes.h"
- #endif
-
- #ifndef __USHAPESDOCUMENT__
- #include "UShapesDocument.h"
- #endif
-
- #ifndef __USHAPEVIEW__
- #include "UShapeView.h"
- #endif
-
- #ifndef __UTEXTSHAPE__
- #include "UTextShape.h"
- #endif
-
- #ifndef __UPICTSHAPE__
- #include "UPictShape.h"
- #endif
-
- // MacApp
-
- #ifndef __UMENUMGR__
- #include <UMenuMgr.h>
- #endif
-
- #ifndef __UMEMORY__
- #include <UMemory.h>
- #endif
-
- #ifndef __UVIEWSERVER__
- #include <UViewServer.h>
- #endif
-
- #ifndef __UWINDOW__
- #include <UWindow.h>
- #endif
-
- #ifndef __UMACAPPGLOBALS__
- #include "UMacAppGlobals.h"
- #endif
-
- #ifndef __UMACAPPUTILITIES__
- #include "UMacAppUtilities.h"
- #endif
-
- // Toolbox
-
- #ifndef __SCRAP__
- #include <Scrap.h>
- #endif
-
- //----------------------------------------------------------------------------------------
- // Globals
-
- TShapeApplication* gShapeApplication;
-
- Boolean gPasteReplacesSelection; // Tells whether Paste should _replace_ the
- // existing selection, or instead simply add
- // new shapes without replacement.
- // Default: false
- // Change its value by using the "More Debug"
- // menu, obtainable by typing Cmd-D.
-
- Boolean gConstrainDrags; // Whether dragging shapes with the mouse
- // should be constrained so that nothing
- // overlaps the view's borders.
- // Default: true
- // Change its value by using the "More Debug"
- // menu, obtainable by typing Cmd-D.
-
- short gStaggerCount; // for SimpleStagger
-
- CCrsrHandle gRainbowArrow;
-
- Boolean gBetterFeedback; // true to invoke BetterFeedback routines
-
- //----------------------------------------------------------------------------------------
- // Resources
-
- // Menu bars for color and for b&w systems
- #define kColorMenuBar 131
- #define kNonColorMenuBar 132
-
- #define kRainbowArrow 140
-
- #define kPickerPrompt 256
-
- const OSType kDocRsrcKind = 'DSTA'; // Resource type for document state
- const short kDocStateID = 1; // Resource id for document state
-
- // Windows
-
- const short kShapeWindowRSRCID = 1005; // Windows used by documents in the application
-
- const short kShapeViewRSRCID = 1006; // Resource id for the shape view template,
- // used when printing & using template views
-
- const short kToolsPaletteRSRCID = 1007; // Resource id for the floating window with
- // tools palette
-
- const short kPatternsPaletteRSRCID = 1008; // Resource id for the floating window with
- // patterns palette
-
- // Menus
- const short mTools = 5; // the Tools menu resource id
- const short mPatterns = 6; // the Patterns menu resource id
- const short mColor = 7; // the Color menu resource id
- const short mMoreDebug = 8; // Menu number for the "More Debug" menu
-
-
- // Command Numbers
-
- #define cArrow 1100
- #define cBox 1101
- #define cCircle 1102
- #define cHBox 1103
- #define cTextShape 1104
-
-
- //========================================================================================
- // CLASS TShapeApplication
- //========================================================================================
- #undef Inherited
- #define Inherited TApplication
-
- #pragma segment AInit
- MA_DEFINE_CLASS_M1(TShapeApplication, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TShapeApplication Constructor
- //----------------------------------------------------------------------------------------
- #pragma segment AInit
-
- TShapeApplication::TShapeApplication()
- {
- if (qNeedsColorQD || gConfiguration.hasColorQD)
- fDisplayedMenus = kColorMenuBar;
- else
- fDisplayedMenus = kColorMenuBar;
- }
-
- //----------------------------------------------------------------------------------------
- // TShapeApplication::IShapeApplication:
- //----------------------------------------------------------------------------------------
- #pragma segment AInit
-
- void TShapeApplication::IShapeApplication()
- {
- this->IApplication(kDocType, kSignature);
- gShapeApplication = this;
-
- // Suppress Linker dead-stripping of these classes
- macroDontDeadStrip(TShapeView);
- macroDontDeadStrip(TToolsPalette);
- macroDontDeadStrip(TPatternsPalette);
-
- macroDontDeadStrip(THackView);
-
- // Copy patterns into global array of patterns
- InitPatternsMenu();
-
- // Now create the floating palette window
- gToolsPaletteWindow = gViewServer->NewTemplateWindow(kToolsPaletteRSRCID, NULL);
- FailNIL(gToolsPaletteWindow);
-
- // Now create the floating Patterns window
- gPatternsWindow = gViewServer->NewTemplateWindow(kPatternsPaletteRSRCID, NULL);
- FailNIL(gPatternsWindow);
-
- // Install our custom tools menu
- TToolsMenu* toolsMenu = new TToolsMenu;
- toolsMenu->IToolsMenu(mTools);
- gToolsMenu = toolsMenu;
-
- // Install our custom pattern menu
- TPatternsMenu* patternsMenu = new TPatternsMenu;
- patternsMenu->IPatternsMenu(mPatterns);
- gPatternsMenu = patternsMenu;
-
- // Install our hack
- THackMenu* controlMenu = new THackMenu;
- controlMenu->IHackMenu(9, 1009);
-
- // Define the prototype shapes
- short id = 0;
- CRect r(10, 10, 28, 30);
-
- TArrowTool* arrowTool = new TArrowTool;
- arrowTool->IArrowTool(r, id);
- SetShapeInArray(arrowTool);
-
- ++id;
- OffsetRect(r, 0, 40);
- TBox* box = new TBox;
- box->IBox(r, id);
- SetShapeInArray(box);
-
- ++id;
- OffsetRect(r, 0, 40);
- TCircle* circle = new TCircle;
- circle->ICircle(r, id);
- SetShapeInArray(circle);
-
- ++id;
- OffsetRect(r, 0, 40);
- THeavyBox* heavyBox = new THeavyBox;
- heavyBox->IHeavyBox(r, id);
- SetShapeInArray(heavyBox);
-
- ++id;
- OffsetRect(r, 0, 40);
- TTextShape* textShape = new TTextShape;
- textShape->ITextShape(r, id);
- SetShapeInArray(textShape);
-
- ++id;
- OffsetRect(r, 0, 40);
- TPictShape* pictShape = new TPictShape;
- pictShape->IPictShape(r, id);
- SetShapeInArray(pictShape);
-
- VPoint newSize(41, GetNumberOfShapes() * 40);
- gToolsPaletteWindow->Resize(newSize, kDontInvalidate);
-
- gPasteReplacesSelection = false;
- gConstrainDrags = true;
- gStaggerCount = 0;
-
- if (qNeedsColorQD || gConfiguration.hasColorQD)
- {
- // Unlike GetCursor, GetCCursor makes a copy of the color cursor resource.
- // Therefore, you should make one call to GetCCursor and multiple calls to SetCCursor.
- gRainbowArrow = GetCCursor(kRainbowArrow);
- FailNIL(gRainbowArrow);
- }
- gBetterFeedback = kBetterFeedbackDesired;
- }
-
- //----------------------------------------------------------------------------------------
- // TShapeApplication::DoMakeDocument:
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
-
- TDocument* TShapeApplication::DoMakeDocument(CommandNumber /*itsCommandNumber*/,
- TFile* itsFile) // Override
- {
- TShapeDocument* aShapeDocument = new TShapeDocument;
- aShapeDocument->IShapeDocument(itsFile);
-
- return aShapeDocument;
- } // TShapeApplication::DoMakeDocument
-
- #if qDebug
- //----------------------------------------------------------------------------------------
- // TShapeApplication::DoCommandKeyEvent - This illustrates how to have a 'Command-key-only'
- // command, i.e. a command which is NOT in a menu, but rather only available when the user
- // types the Command key and another key concurrently. In this example, the user presses
- // 'Command-D' (the D can be in upper or lower case) to request that the special "More
- // Debug" menu be put up (or taken down if it was already up).
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
-
- void TShapeApplication::DoCommandKeyEvent(TToolboxEvent* event) // Override
- {
- if (UprChar(event->fCharacter) == 'D')
- this->DoMenuCommand(cToggleMoreDebugMenu);
- else
- Inherited::DoCommandKeyEvent(event);
- } // TShapeApplication::DoCommandKeyEvent
- #endif
-
- #if qDebug
- //----------------------------------------------------------------------------------------
- // TShapeApplication::DoMenuCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
-
- void TShapeApplication::DoMenuCommand(CommandNumber aCommandNumber) // Override
- {
- switch (aCommandNumber)
- {
- case cPasteReplacesSelection:
- gPasteReplacesSelection = !gPasteReplacesSelection;
- break;
-
- case cConstrainDrags:
- gConstrainDrags = !gConstrainDrags;
- break;
-
- case cToggleMoreDebugMenu:
- {
- if (GetMenuHandle(mMoreDebug) == NULL) // menu not currently up - put it up
- InsertMenu(MAGetMenu(mMoreDebug), 0);
- else // menu currently up - take it down
- DeleteMenu(mMoreDebug);
- InvalidateMenuBar(); // Get it redrawn
- break;
- }
-
- default:
- Inherited::DoMenuCommand(aCommandNumber);
- }
- } // TShapeApplication::DoMenuCommand
- #endif
-
- #if qDebug
- //----------------------------------------------------------------------------------------
- // TShapeApplication::DoSetupMenus:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TShapeApplication::DoSetupMenus() // Override
- {
- Inherited::DoSetupMenus();
- EnableCheck(cPasteReplacesSelection, true, gPasteReplacesSelection);
- EnableCheck(cConstrainDrags, true, gConstrainDrags);
- }
- #endif
-
- //----------------------------------------------------------------------------------------
- // TShapeApplication::MakeViewForAlienClipboard: Launch a view to represent the data found
- // in the Clipboard at application start-up time, or when switching back in, or when
- // returning from a Desk Accessory.
- //----------------------------------------------------------------------------------------
- #pragma segment AClipboard
-
- TView* TShapeApplication::MakeViewForAlienClipboard() // Override
- {
- TView* clipView = NULL;
-
- // Before doing anything else, make sure the scrap contains shapes
- long offset;
- long result;
- result = GetScrap(NULL, kShapeClipType, &offset);
- if (result <= 0)
- return Inherited::MakeViewForAlienClipboard();
-
- // found my kind of data
- MAVolatileInit(TShapeDocument*, clipShapeDoc, NULL);
- FailInfo fi;
- Try(fi)
- {
- clipShapeDoc = new TShapeDocument;
- clipShapeDoc->IShapeDocument(NULL);
-
- clipView = clipShapeDoc->MakeClipView();
- fi.Success();
- }
- else // Recover
- {
- clipShapeDoc = (TShapeDocument*) FreeIfObject(clipShapeDoc);
- fi.ReSignal();
- }
- return clipView;
- }
-
-